package com.unf.edu.rms.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.unf.edu.rms.dao.Faculty;
import com.unf.edu.rms.dao.Thesis;
import com.unf.edu.rms.dao.ThesisCommittee;
import com.unf.edu.rms.dao.ThesisStatus;

@Service
public class ThesisService {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Transactional
	public List<Thesis> getThesisList()
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "FROM Thesis";
		Query query = session.createQuery(hql);
		List <Thesis> thesisList = (List<Thesis>)query.list();
		return thesisList;
	}
	
	
	@Transactional
	public void addNewThesis(Thesis thesis)
	{
		Session session = sessionFactory.getCurrentSession();
		session.save(thesis);
		
	}
        
    @Transactional
    public Thesis getThesisById(int thesisId){
    	Session session = sessionFactory.getCurrentSession();
		String hql = "FROM Thesis where thesisId=:thesisId";
		Query query = session.createQuery(hql);
		query.setInteger("thesisId", thesisId);
		Thesis thesis = (Thesis)query.list().get(0);
		return thesis;
    }
        
    @Transactional
	public void updateThesis(Thesis thesis)
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "FROM Thesis where thesisId=:thesisId";
		Query query = session.createQuery(hql);
		query.setInteger("thesisId", thesis.getThesisId());
		session.update(thesis);
		
	}
}
